﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AlgorithmResult;
using System.Data;
using System.Windows.Forms;

namespace TripletSegmentationGUI
{
    public class StandartDeviationRate : StandartDeviation
    {
        public StandartDeviationRate(DataTable table, Result result, Dictionary<String, int> CodonMap)
            : base(table, result, CodonMap)
        {
            
        }
        public override double CalculateStandardDeviation()
        {
            try
            {
                double sum = 0;
                for (int i = 0; i < result.NumOfBoundaries; ++i)
                { 
                    sum += Math.Pow(((float)(result.SimilarityToAncientCodon[i] ) - (float)table.Rows[CodonMap[result.ArchreTriplets[i]]][DataTableResult.STR_AverageFragmentSimilarity]/100), 2);
                }
                sigma = Math.Pow((double)((double)sum / (double)result.NumOfBoundaries), 0.5);

                return sigma;
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
            return 0;
        }
    }
}
